#include <Files.h>
/* This program copies both forks of a particular file. */
main()
{
short srcRef, destRef;
quitErr( GetFInfo( "\pHD 20:MyFile", 0, &fi ) ); CreateResFile will create both forks of the file, it will fail silently if the file already exists and has a non-empty resource fork. An alternative
call worked
*/
quitErr( Create( "\pCopyOfMyFile", 0, fi.fdCreator, fi.fdType ) ); quitErr( FSOpen( "\pHD 20:MyFile", 0, &srcRef ) ); quitErr( FSOpen( "\pHD 20:CopyOfMyFile", 0, &destRef ) ); CopyFile( srcRef, destRef );
quitErr( OpenRF( "\pmyfile", 0, &srcRef ) ); quitErr( OpenRF( "\pCopyOfMyFile", 0, &destRef ) ); CopyFile( srcRef, destRef );
}
/* --- function copies all bytes from one open file to another --- */
CopyFile( short src, short dest )
/* src, dest = file reference numbers */
{
long curPos, srcSize, count;
short err;
char theBuf[512];
quitErr( GetEOF( src, &srcSize ) ); if ( srcSize == 0 )
return(0);
quitErr( GetFPos( src, &curPos ) ); if ( curPos >= srcSize ) break; /* exit when past EOF */
count = 512;
err = FSRead( src, & count, theBuf ); if ( err != eofErr ) quitErr( err ); /* ok to go past EOF */
quitErr( FSWrite( dest, & count, theBuf ) ); /* same count */ }
SetEOF( dest, srcSize ); [TOKEN:12074] adjust to correct end-of-file */ }
/* --- Error 'checking'; quits on any non-zero value --- */
quitErr( short errCode )
{
if ( errCode == 0 )
return(0);
printf("Error %d\n", errCode );
}